package com.uyayo.core.controller;

import com.uyayo.framework.message.model.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.LocaleResolver;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.Locale;

/**
 * 
 * <p>
 * Title: LanguageController
 * </p>
 * <p>
 * Description:主页的Controller
 * </p>
 * <p>
 * Company: www.lelekeji.com
 * </p>
 * 
 * @author 乐乐科技.胡逢君
 * @date 2016-4-23下午4:03:35
 * @version 1.0
 */
@Controller
@RequestMapping("language")
public class LanguageController{
	
	@Autowired
	private LocaleResolver resolver;
		
	/**
	 * 语言切换
	 */
	@ResponseBody
	@RequestMapping(method=RequestMethod.GET)
	public Result language(HttpServletRequest request,HttpServletResponse response,String lang,String redirectUrl){
		
		if(lang==null|| "".equals(lang)){
			return Result.success();
		}else{
			lang=lang.toLowerCase();
			if("zh_cn".equals(lang)){
				resolver.setLocale(request, response, Locale.CHINA );
			}else if("en".equals(lang)){
				resolver.setLocale(request, response, Locale.ENGLISH );
			}else{
				resolver.setLocale(request, response, Locale.CHINA );
			}
		}
		
		return Result.success();
	}
	
}
